<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑用户 - 电影院管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background-color: #f5f5f5;
            line-height: 1.6;
        }
        
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1rem 0;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .nav {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }
        
        .logo {
            font-size: 24px;
            font-weight: bold;
        }
        
        .nav-links {
            display: flex;
            gap: 30px;
        }
        
        .nav-links a {
            color: white;
            text-decoration: none;
            font-weight: 500;
            transition: opacity 0.3s;
        }
        
        .nav-links a:hover {
            opacity: 0.8;
        }
        
        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        
        .edit-section {
            background: white;
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        
        .section-title {
            font-size: 24px;
            color: #333;
            margin-bottom: 20px;
            border-bottom: 3px solid #667eea;
            padding-bottom: 10px;
            text-align: center;
        }
        
        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
            margin-bottom: 20px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #333;
        }
        
        .form-group input,
        .form-group select {
            width: 100%;
            padding: 12px;
            border: 2px solid #e1e1e1;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        .form-group input:focus,
        .form-group select:focus {
            outline: none;
            border-color: #667eea;
        }
        
        .form-group input[readonly] {
            background-color: #f8f9fa;
            color: #666;
        }
        
        .checkbox-group {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 20px;
        }
        
        .checkbox-group input[type="checkbox"] {
            width: auto;
        }
        
        .btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 8px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-size: 14px;
            font-weight: 500;
            transition: transform 0.2s;
            margin-right: 10px;
        }
        
        .btn:hover {
            transform: translateY(-2px);
        }
        
        .btn-sm {
            padding: 6px 12px;
            font-size: 12px;
        }
        
        .btn-secondary {
            background: #6c757d;
        }
        
        .btn-danger {
            background: #dc3545;
        }
        
        .btn-actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
            margin-top: 30px;
        }
        
        .alert {
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 8px;
            text-align: center;
        }
        
        .alert-success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .alert-error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .password-actions {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 20px;
            border: 1px solid #e1e1e1;
        }
        
        .password-actions h4 {
            color: #333;
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
    <header class="header">
        <nav class="nav">
            <div class="logo">🎬 管理员控制台</div>
            <div class="nav-links">
                <a href="/admin/dashboard">控制台</a>
                <a href="/admin/users">用户管理</a>
                <a href="/admin/rooms">放映厅管理</a>
                <a href="/admin/logs">系统日志</a>
            </div>
            <div class="user-info">
                <span th:text="'管理员：' + ${currentUser != null ? currentUser.username : '未登录'}">管理员</span>
                <a href="/auth/logout" class="btn btn-sm">退出登录</a>
            </div>
        </nav>
    </header>
    
    <div class="container">
        <div class="edit-section">
            <h2 class="section-title">编辑用户</h2>
            
            <!-- 错误消息 -->
            <div th:if="${errorMessage}" class="alert alert-error">
                <span th:text="${errorMessage}"></span>
            </div>
            
            <!-- 成功消息 -->
            <div th:if="${successMessage}" class="alert alert-success">
                <span th:text="${successMessage}"></span>
            </div>
            
            <!-- 密码管理区域 -->
            <div class="password-actions">
                <h4>密码管理</h4>
                <form th:action="@{/admin/users/reset-password}" method="post" style="display: inline;">
                    <input type="hidden" name="userId" th:value="${user.userId}" />
                    <button type="submit" class="btn btn-danger" 
                            onclick="return confirm('确定要重置该用户的密码为123456吗？用户下次登录时必须修改密码。')">
                        重置密码为123456
                    </button>
                </form>
                <p style="margin-top: 10px; color: #666; font-size: 14px;">重置后用户必须在下次登录时修改密码</p>
            </div>

            <form th:action="@{/admin/users/edit}" method="post" th:object="${user}">
                <input type="hidden" th:field="*{userId}" />
                
                <div class="form-row">
                    <div class="form-group">
                        <label for="username">👤 用户名</label>
                        <input type="text" id="username" th:field="*{username}" readonly>
                    </div>
                    
                    <div class="form-group">
                        <label for="phoneNumber">📱 手机号码</label>
                        <input type="tel" id="phoneNumber" th:field="*{phoneNumber}" 
                               pattern="1[0-9]{10}" 
                               title="请输入11位手机号码，以1开头" 
                               maxlength="11" 
                               required>
                        <small style="color: #666; font-size: 12px;">请输入11位手机号码，以1开头</small>
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-group">
                        <label for="role">🏷️ 用户角色</label>
                        <select id="role" th:field="*{role}">
                            <option value="manager">经理</option>
                            <option value="admin">管理员</option>
                            <option value="receptionist">前台</option>
                        </select>
                    </div>
                    
                    <div class="form-group">
                        <label for="registrationTime">📅 注册时间</label>
                        <input type="text" id="registrationTime" 
                               th:value="${#temporals.format(user.registrationTime, 'yyyy-MM-dd HH:mm:ss')}" readonly>
                    </div>
                </div>
                
                <div class="checkbox-group">
                    <input type="checkbox" id="mustChangePassword" th:field="*{mustChangePassword}">
                    <label for="mustChangePassword">🔑 要求用户下次登录时修改密码</label>
                </div>
                
                <div class="btn-actions">
                    <a th:href="@{/admin/users}" class="btn btn-secondary">
                        ← 返回
                    </a>
                    <button type="submit" class="btn">
                        💾 保存修改
                    </button>
                </div>
            </form>
        </div>
    </div>
    
    <script>
        // 手机号实时验证
        document.addEventListener('DOMContentLoaded', function() {
            const phoneInput = document.getElementById('phoneNumber');
            
            phoneInput.addEventListener('input', function() {
                const phone = this.value;
                const isValid = /^1[0-9]{10}$/.test(phone);
                
                // 移除之前的错误提示
                const existingError = document.getElementById('phoneError');
                if (existingError) existingError.remove();
                
                if (phone.length > 0 && !isValid) {
                    this.style.borderColor = '#ff4444';
                    const errorMsg = document.createElement('small');
                    errorMsg.id = 'phoneError';
                    errorMsg.style.color = '#ff4444';
                    errorMsg.style.fontSize = '12px';
                    errorMsg.style.display = 'block';
                    errorMsg.style.marginTop = '5px';
                    errorMsg.textContent = '手机号格式不正确，请输入11位数字，以1开头';
                    this.parentNode.appendChild(errorMsg);
                } else {
                    this.style.borderColor = phone.length === 11 && isValid ? '#4CAF50' : '';
                }
            });
            
            // 只允许输入数字
            phoneInput.addEventListener('keypress', function(e) {
                if (!/[0-9]/.test(e.key) && e.key !== 'Backspace' && e.key !== 'Delete' && e.key !== 'Tab') {
                    e.preventDefault();
                }
            });
        });
    </script>
</body>
</html>